<div class="doc-item" id="doc-1037"><h2 class="doc-item-name">maybe-t<span class="namespace">(clojure.contrib.monads)</span></h2><ul class="var-arglists"><li>(<span class="var-name">maybe-t</span>  m)</li><li>(<span class="var-name">maybe-t</span> m nothing)</li><li>(<span class="var-name">maybe-t</span> m nothing which-m-plus)</li></ul><div class="var-docstring"><p>Monad transformer that transforms a monad m into a monad in which
   the base values can be invalid (represented by nothing, which defaults
   to nil). The third argument chooses if m-zero and m-plus are inherited
   from the base monad (use :m-plus-from-base) or adopt maybe-like
   behaviour (use :m-plus-from-transformer). The default is :m-plus-from-base
   if the base monad m has a definition for m-plus, and
   :m-plus-from-transformer otherwise.</p></div><div class="var-source"><pre>; clojure/contrib/monads.clj:455
(defn maybe-t
  ([m] (maybe-t m nil :m-plus-default))
  ([m nothing] (maybe-t m nothing :m-plus-default))
  ([m nothing which-m-plus]
   (monad-transformer m which-m-plus
     [m-result (with-monad m m-result)
      m-bind   (with-monad m
		 (fn m-bind-maybe-t [mv f]
		   (m-bind mv
			   (fn [x]
			     (if (identical? x nothing)
			       (m-result nothing)
			       (f x))))))
      m-zero   (with-monad m (m-result nothing))
      m-plus   (with-monad m
	         (fn m-plus-maybe-t [&amp; mvs]
		   (if (empty? mvs)
		     (m-result nothing)
		     (m-bind (first mvs)
			     (fn [v]
			       (if (= v nothing)
				 (apply m-plus-maybe-t (rest mvs))
				 (m-result v)))))))
      ])))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>